package Accessors;

import android.app.ProgressDialog;
import android.content.Context;
import Callbacks.AbstractCallback;
import Models.Recipe;
import Presenter.RecipePresenter;

@SuppressWarnings("rawtypes")
public class RecipeAccessor extends AbstractAccessor<Recipe,RecipePresenter,AbstractCallback> {
	private final String NAME = "recipes";
	private final String DIALOG = "Recipe(s)";
	
	private final static RecipePresenter presenter = new RecipePresenter();
	
	//Modal dialog variable.
	ProgressDialog modalDialog = null;
	
	public RecipeAccessor(AbstractCallback callback){
		super(presenter, callback);
	}
	
	//Public access functions.
	public void getAllItems(final Context context){
		String dialog = "Loading " + DIALOG + " List...";
		String rfString = NAME  + "/runNamedQuery/Recipes.findAll";
		super.getAllItems(context, dialog, rfString);
	}
	
	public void getItem(final int id, final Context context){
		String dialog = "Loading " + DIALOG + "...";
		String rfString = NAME + "/" + Integer.toString(id);
		super.getItem(context, dialog, rfString);
	}
	
	public void doItemUpdate(final Recipe item, final Context context){
		String dialog = "Updating " + DIALOG + "...";
		String rfString = NAME;
		super.doItemUpdate(item, context, dialog, rfString);
	}
	
	public void doItemInsert(final Recipe item, final Context context){
		String dialog = "Inserting " + DIALOG + "...";
		String rfString = NAME;
		super.doItemInsert(item, context, dialog, rfString);
	}
	
	/*private class DownloadFileTask extends AsyncTask<String, Void, String> {
    	@Override
        protected String doInBackground(String... urls) {

            try {
                return RESTfulConnect.getFile(urls[0], urls[1], urls[2]);
            } catch (IOException e) {
            	e.printStackTrace();
            	return "Connection Error";
            }
        }
    	@SuppressWarnings("unchecked")
		@Override
        protected void onPostExecute(String result) {
    		T t = (T)presenter.tryJSONParse(result);
    		modalDialog.dismiss();
    		ArrayList<T> items = new ArrayList<T>();
    		callback.callback(t, RFAT.GET_SINGLE, items);
        }
    }*/
}
